﻿
Option Strict On

Imports osi.root.constants
Imports osi.root.connector
Imports osi.root.delegates
Imports osi.root.formation
Imports osi.root.procedure
Imports osi.root.utils
Imports osi.service.argument

Public Class block_idevice_pool_wrapper(Of T As idevice_pool(Of block))
    Inherits idevice_pool_adapter(Of block, block, T)

    Public Sub New(ByVal f As T)
        MyBase.New(f)
    End Sub

    Protected NotOverridable Overrides Function to_dev_to_from_dev(ByVal i As block, ByRef o As block) As Boolean
        Return block_wrapper.unwrap(i, o)
    End Function
End Class

<global_init(global_init_level.services)>
Public Class block_idevice_pool_wrapper
    Inherits block_idevice_pool_wrapper(Of idevice_pool(Of block))

    Public Sub New(ByVal f As idevice_pool(Of block))
        MyBase.New(f)
    End Sub

    Private Shared Sub init()
        assert(device_wrapper.register(Function(v As var,
                                                i As idevice_pool(Of block)) As idevice_pool(Of block)
                                           Return New block_idevice_pool_wrapper(i)
                                       End Function))
    End Sub
End Class

Public Class block_isync_device_pool_wrapper(Of T As isync_device_pool(Of block))
    Inherits isync_device_pool_adapter(Of block, block, T)

    Private ReadOnly f As _do_val_ref(Of block, block, Boolean)

    Public Sub New(ByVal i As T, ByVal v As var)
        MyBase.New(i)
        assert(block_wrapper.bind_wrap(v, f))
        assert(Not f Is Nothing)
    End Sub

    Protected NotOverridable Overrides Function from_dev_to_to_dev(ByVal i As block, ByRef o As block) As Boolean
        Return f(i, o)
    End Function

    Protected NotOverridable Overrides Function to_dev_to_from_dev(ByVal i As block, ByRef o As block) As Boolean
        Return block_wrapper.unwrap(i, o)
    End Function
End Class

<global_init(global_init_level.services)>
Public Class block_isync_device_pool_wrapper
    Inherits block_isync_device_pool_wrapper(Of isync_device_pool(Of block))

    Public Sub New(ByVal i As isync_device_pool(Of block), ByVal v As var)
        MyBase.New(i, v)
    End Sub

    Private Shared Sub init()
        assert(device_wrapper.register(Function(v As var,
                                                i As isync_device_pool(Of block)) As isync_device_pool(Of block)
                                           Return New block_isync_device_pool_wrapper(i, v)
                                       End Function))
    End Sub
End Class

Public Class block_iasync_device_pool_wrapper(Of T As iasync_device_pool(Of block))
    Inherits iasync_device_pool_adapter(Of block, block, T)

    Private ReadOnly f As Func(Of block, pointer(Of block), event_comb)

    Public Sub New(ByVal i As T, ByVal v As var)
        MyBase.New(i)
        assert(block_wrapper.bind_wrap(v, f))
        assert(Not f Is Nothing)
    End Sub

    Protected NotOverridable Overrides Function from_dev_to_to_dev(ByVal i As block,
                                                                   ByVal o As pointer(Of block)) As event_comb
        Return f(i, o)
    End Function

    Protected NotOverridable Overrides Function to_dev_to_from_dev(ByVal i As block, ByRef o As block) As Boolean
        Return block_wrapper.unwrap(i, o)
    End Function
End Class

<global_init(global_init_level.services)>
Public Class block_iasync_device_pool_wrapper
    Inherits block_iasync_device_pool_wrapper(Of iasync_device_pool(Of block))

    Public Sub New(ByVal i As iasync_device_pool(Of block), ByVal v As var)
        MyBase.New(i, v)
    End Sub

    Private Shared Sub init()
        assert(device_wrapper.register(Function(v As var,
                                                i As iasync_device_pool(Of block)) As iasync_device_pool(Of block)
                                           Return New block_iasync_device_pool_wrapper(i, v)
                                       End Function))
    End Sub
End Class

Public Class block_new_device_event_isync_device_pool_wrapper(Of T As new_device_event_isync_device_pool(Of block))
    Inherits new_device_event_isync_device_pool_adapter(Of block, block, T)

    Private ReadOnly f As _do_val_ref(Of block, block, Boolean)

    Public Sub New(ByVal i As T, ByVal v As var)
        MyBase.New(i)
        assert(block_wrapper.bind_wrap(v, f))
        assert(Not f Is Nothing)
    End Sub

    Protected NotOverridable Overrides Function from_dev_to_to_dev(ByVal i As block, ByRef o As block) As Boolean
        Return f(i, o)
    End Function

    Protected NotOverridable Overrides Function to_dev_to_from_dev(ByVal i As block, ByRef o As block) As Boolean
        Return block_wrapper.unwrap(i, o)
    End Function
End Class

<global_init(global_init_level.services)>
Public Class block_new_device_event_isync_device_pool_wrapper
    Inherits block_new_device_event_isync_device_pool_wrapper(Of new_device_event_isync_device_pool(Of block))

    Public Sub New(ByVal i As new_device_event_isync_device_pool(Of block), ByVal v As var)
        MyBase.New(i, v)
    End Sub

    Private Shared Sub init()
        assert(device_wrapper.register(Function(v As var,
                                                i As new_device_event_isync_device_pool(Of block)) _
                                               As new_device_event_isync_device_pool(Of block)
                                           Return New block_new_device_event_isync_device_pool_wrapper(i, v)
                                       End Function))
    End Sub
End Class
